#include <vector>
#include <complex>
#include <gtest/gtest.h>
#include "module_psi/kernels/memory_op.h"
#include "module_hamilt_pw/hamilt_pwdft/kernels/vnl_op.h"

class TestSrcPWVnlMultiDevice : public ::testing::Test
{
protected:
    // xx = tf.random.uniform([100], minval=-4, maxval=4, dtype = tf.float64)

    const psi::DEVICE_CPU * cpu_ctx = {};
    const psi::DEVICE_GPU * gpu_ctx = {};

    int ntype = 1, npw = 59, npwx = 70, nhm = 4, NQX = 298, tab_2 = 10, tab_3 = 298;

    double DQ = 0.01, tpiba = 0.61599855952741045;

    std::complex<double> NEG_IMAG_UNIT = {0, -1};

    std::vector<int> atom_na {2};
    std::vector<int> atom_nb {2};
    std::vector<int> atom_nh {4};

    std::vector<double> gk = {2, -2, -2, 1, -1, -1, 0, 0, 0, -1, 1, 1, -2, 2, 2, 2, -2, 0, 1, -1, 1, 0, 0, 2, -1, 1, 3, 2, -2, 2, 1, -1, 3, -1, 1, -3, -2, 2, -2, 1, -1, -3, 0, 0, -2, -1, 1, -1, -2, 2, 0, 2, 0, -2, 1, 1, -1, 0, 2, 0, -1, 3, 1, 3, -1, -1, 2, 0, 0, 1, 1, 1, 0, 2, 2, 3, -1, 1, 2, 0, 2, 1, 1, 3, 1, 1, -3, 0, 2, -2, -1, 3, -1, 2, 2, -2, 1, 3, -1, 3, 1, -1, 2, 2, 0, 1, 3, 1, 3, 1, 1, 2, 2, 2, -1, -3, 1, -2, -2, 2, -2, -2, -2, -3, -1, -1, -1, -3, -1, -2, -2, 0, -3, -1, 1, 1, -3, -1, 0, -2, 0, -1, -1, 1, -2, 0, 2, 1, -3, 1, 0, -2, 2, -1, -1, 3, -1, -1, -3, -2, 0, -2, -3, 1, -1, 0, -2, -2, -1, -1, -1, -2, 0, 0, -3, 1, 1};
    std::vector<double> ylm = {0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, 0.282094791774, -0.282094791774, -0.282094791774, 0, 0.282094791774, 0.282094791774, 0, 0.282094791774, 0.488602511903, 0.441957600984, 0.282094791774, 0.441957600984, -0.441957600984, -0.282094791774, -0.441957600984, -0.488602511903, -0.282094791774, 0, -0.345494149471, -0.282094791774, 0, 0.147319200328, -0.147319200328, 0, 0.282094791774, 0.345494149471, 0.147319200328, 0.345494149471, 0.441957600984, -0.441957600984, -0.345494149471, -0.147319200328, -0.282094791774, -0.147319200328, -0.147319200328, 0, 0.147319200328, 0.147319200328, 0.282094791774, 0.147319200328, 0.282094791774, -0.282094791774, -0.147319200328, -0.147319200328, 0, 0.147319200328, -0.147319200328, 0, 0.282094791774, 0.345494149471, 0.147319200328, 0.345494149471, 0.441957600984, -0.441957600984, -0.345494149471, -0.147319200328, -0.345494149471, -0.282094791774, 0, 0.147319200328, -0.282094791774, -0.282094791774, -2.99182751129e-17, 0.282094791774, 0.282094791774, -0.345494149471, -0.282094791774, -0, 0.147319200328, -0.282094791774, -0.147319200328, 0.147319200328, 0.282094791774, -0.147319200328, -0, 0.282094791774, 0.345494149471, -0.345494149471, -0.282094791774, -2.99182751129e-17, 0.147319200328, -0.441957600984, -0.488602511903, -0.282094791774, -2.11554152137e-17, -0.441957600984, -0.345494149471, -0.147319200328, -0.147319200328, -2.11554152137e-17, 0.147319200328, -0.282094791774, -0.147319200328, -0.441957600984, -0.345494149471, -0.147319200328, -0.441957600984, -0.282094791774, 0.147319200328, 0.282094791774, 0.282094791774, 0.441957600984, 0.147319200328, 0.345494149471, 0.441957600984, -0.147319200328, -2.99182751129e-17, 0.282094791774, 0.345494149471, -0.147319200328, -2.11554152137e-17, 0.147319200328, 0.147319200328, 0.345494149471, 0.441957600984, -2.11554152137e-17, 0.282094791774, 0.488602511903, 0.441957600984, 0.282094791774, 0.282094791774, -0.488602511903, -0.282094791774, -0.282094791774, 0.345494149471, 0.282094791774, -0, -0.147319200328, 0.282094791774, 0.147319200328, -0.147319200328, -0.282094791774, 0.147319200328, -0, -0.282094791774, -0.345494149471, -0, -0.282094791774, -0.488602511903, -0.441957600984, 0.147319200328, -0, -0.282094791774, -0.345494149471, 0.147319200328, -0, -0.147319200328, -0.147319200328, -0.345494149471, -0.441957600984, -0.282094791774, -0.441957600984, -0.147319200328, -0.345494149471, -0.441957600984, -0.147319200328, -0.282094791774, 0.441957600984, 0.282094791774, 0.282094791774, 0.147319200328, 0.441957600984, 0.345494149471, 0.147319200328, 0.441957600984, 0.488602511903, 0.282094791774, -4.23108304274e-17, 0.441957600984, 0.345494149471, 0.147319200328, 0.147319200328, -4.23108304274e-17, -0.147319200328, 0.345494149471, 0.282094791774, -5.98365502257e-17, -0.147319200328};
    std::vector<double> indv = {0, 1, 1, 1};
    std::vector<double> nhtol = {0, 1, 1, 1};
    std::vector<double> nhtolm = {0, 1, 2, 3};
    std::vector<double> tab = {1.35887670829, 1.35885922161, 1.35880676218, 1.35871933185, 1.35859693367, 1.35843957194, 1.35824725217, 1.35801998112, 1.35775776677, 1.35746061833, 1.35712854625, 1.35676156222, 1.35635967919, 1.35592291133, 1.35545127408, 1.35494478413, 1.35440345943, 1.3538273192, 1.35321638393, 1.35257067538, 1.3518902166, 1.35117503195, 1.35042514704, 1.34964058883, 1.34882138557, 1.34796756682, 1.3470791635, 1.34615620783, 1.34519873341, 1.34420677515, 1.34318036935, 1.3421195537, 1.34102436722, 1.33989485038, 1.338731045, 1.33753299434, 1.33630074309, 1.33503433735, 1.33373382469, 1.33239925411, 1.3310306761, 1.32962814261, 1.3281917071, 1.32672142452, 1.32521735133, 1.32367954555, 1.3221080667, 1.32050297587, 1.31886433572, 1.31719221048, 1.31548666597, 1.31374776962, 1.31197559048, 1.31017019921, 1.30833166813, 1.30646007122, 1.30455548412, 1.30261798416, 1.30064765035, 1.29864456342, 1.29660880583, 1.29454046177, 1.29243961717, 1.29030635973, 1.28814077893, 1.28594296603, 1.28371301408, 1.28145101798, 1.27915707442, 1.27683128194, 1.27447374094, 1.27208455367, 1.26966382428, 1.26721165878, 1.2647281651, 1.26221345307, 1.25966763445, 1.25709082294, 1.25448313416, 1.25184468572, 1.24917559718, 1.24647599008, 1.24374598795, 1.24098571631, 1.23819530269, 1.23537487665, 1.23252456976, 1.22964451563, 1.2267348499, 1.22379571028, 1.22082723654, 1.21782957048, 1.21480285602, 1.21174723913, 1.20866286787, 1.20554989239, 1.20240846494, 1.19923873988, 1.19604087365, 1.19281502484, 1.18956135411, 1.18628002427, 1.18297120024, 1.17963504907, 1.1762717399, 1.17288144405, 1.16946433493, 1.16602058809, 1.1625503812, 1.15905389408, 1.15553130864, 1.15198280894, 1.14840858116, 1.14480881361, 1.14118369668, 1.13753342293, 1.13385818697, 1.13015818557, 1.12643361756, 1.12268468389, 1.11891158758, 1.11511453374, 1.11129372955, 1.10744938426, 1.10358170919, 1.09969091768, 1.09577722512, 1.09184084895, 1.0878820086, 1.08390092553, 1.07989782316, 1.07587292693, 1.07182646422, 1.0677586644, 1.06366975874, 1.05955998047, 1.05542956471, 1.05127874848, 1.0471077707, 1.04291687211, 1.03870629533, 1.0344762848, 1.03022708675, 1.0259589492, 1.02167212197, 1.01736685658, 1.01304340631, 1.00870202613, 1.0043429727, 0.999966504333, 0.995572880983, 0.991162364215, 0.986735217184, 0.982291704608, 0.977832092742, 0.973356649357, 0.968865643707, 0.964359346507, 0.959838029904, 0.955301967448, 0.950751434066, 0.946186706031, 0.941608060935, 0.937015777657, 0.932410136332, 0.927791418326, 0.923159906197, 0.918515883669, 0.913859635598, 0.909191447941, 0.90451160772, 0.899820402992, 0.895118122815, 0.890405057212, 0.885681497138, 0.880947734445, 0.876204061849, 0.87145077289, 0.8666881619, 0.861916523966, 0.857136154893, 0.852347351167, 0.847550409919, 0.842745628887, 0.83793330638, 0.833113741237, 0.828287232791, 0.823454080831, 0.818614585563, 0.813769047569, 0.808917767772, 0.804061047394, 0.799199187918, 0.794332491046, 0.789461258662, 0.784585792791, 0.779706395561, 0.774823369158, 0.769937015789, 0.765047637644, 0.76015553685, 0.755261015434, 0.750364375282, 0.745465918098, 0.740565945362, 0.735664758293, 0.730762657802, 0.725859944458, 0.720956918442, 0.71605387951, 0.711151126949, 0.706248959538, 0.701347675507, 0.696447572497, 0.691548947519, 0.686652096913, 0.681757316307, 0.676864900579, 0.671975143817, 0.667088339275, 0.662204779337, 0.657324755475, 0.652448558213, 0.647576477082, 0.642708800587, 0.637845816161, 0.632987810134, 0.628135067687, 0.623287872821, 0.618446508312, 0.613611255677, 0.608782395136, 0.603960205573, 0.599144964503, 0.59433694803, 0.589536430814, 0.584743686033, 0.579958985348, 0.57518259887, 0.570414795119, 0.565655840996, 0.560906001741, 0.556165540907, 0.55143472032, 0.54671380005, 0.542003038373, 0.537302691744, 0.532613014763, 0.527934260139, 0.523266678668, 0.518610519191, 0.513966028572, 0.509333451666, 0.504713031287, 0.500105008181, 0.495509620997, 0.490927106259, 0.486357698338, 0.481801629426, 0.477259129506, 0.472730426332, 0.468215745397, 0.463715309911, 0.459229340775, 0.454758056558, 0.450301673476, 0.445860405361, 0.441434463647, 0.437024057342, 0.432629393012, 0.428250674755, 0.423888104181, 0.419541880398, 0.415212199985, 0.410899256978, 0.406603242851, 0.402324346497, 0.398062754214, 0.393818649684, 0.389592213961, 0.385383625455, 0.381193059916, 0.377020690419, 0.372866687354, 0.368731218409, 0.364614448561, 0.360516540059, 0.356437652421, 0.352377942415, 0.348337564052, 0.34431666858, 0.340315404467, 0.336333917401, 0.332372350276, 0.32843084319, 0.324509533432, 0.320608555482, 0.316728041001, 0, 0.00229127145945, 0.00458242154002, 0.0068733288568, 0.00916387201284, 0.0114539295932, 0.0137433801588, 0.0160321022407, 0.0183199743343, 0.0206068748933, 0.0228926823238, 0.0251772749793, 0.0274605311545, 0.0297423290799, 0.0320225469169, 0.034301062752, 0.036577754592, 0.038852500359, 0.0411251778856, 0.04339566491, 0.0456638390718, 0.0479295779075, 0.0501927588466, 0.0524532592073, 0.054710956193, 0.0569657268888, 0.0592174482581, 0.0614659971394, 0.0637112502438, 0.0659530841522, 0.0681913753129, 0.0704260000397, 0.0726568345098, 0.0748837547627, 0.0771066366985, 0.0793253560773, 0.0815397885182, 0.0837498094992, 0.0859552943571, 0.0881561182875, 0.0903521563458, 0.0925432834478, 0.0947293743711, 0.0969103037565, 0.0990859461101, 0.101256175806, 0.103420867087, 0.105579894071, 0.10773313075, 0.109880450999, 0.112021728575, 0.114156837124, 0.116285650186, 0.118408041201, 0.12052388351, 0.122633050368, 0.124735414943, 0.126830850328, 0.128919229548, 0.131000425563, 0.133074311282, 0.135140759565, 0.137199643236, 0.139250835093, 0.141294207913, 0.143329634464, 0.145356987517, 0.147376139856, 0.149386964285, 0.151389333645, 0.153383120824, 0.155368198766, 0.15734444049, 0.159311719095, 0.16126990778, 0.163218879857, 0.165158508758, 0.167088668061, 0.169009231494, 0.170920072956, 0.172821066534, 0.174712086512, 0.176593007394, 0.178463703919, 0.180324051073, 0.182173924115, 0.184013198587, 0.185841750335, 0.187659455527, 0.189466190672, 0.191261832639, 0.193046258672, 0.194819346416, 0.196580973934, 0.198331019723, 0.20006936274, 0.20179588242, 0.203510458697, 0.205212972024, 0.206903303395, 0.208581334368, 0.210246947083, 0.211900024288, 0.213540449357, 0.215168106317, 0.216782879865, 0.218384655395, 0.219973319017, 0.221548757586, 0.223110858717, 0.224659510814, 0.226194603091, 0.227716025597, 0.229223669237, 0.230717425798, 0.232197187971, 0.233662849377, 0.235114304587, 0.23655144915, 0.237974179615, 0.239382393554, 0.240775989587, 0.242154867407, 0.243518927801, 0.244868072679, 0.246202205091, 0.247521229256, 0.248825050584, 0.250113575701, 0.251386712471, 0.25264437002, 0.253886458759, 0.25511289041, 0.256323578027, 0.257518436018, 0.25869738017, 0.259860327673, 0.261007197139, 0.262137908628, 0.263252383667, 0.264350545275, 0.265432317985, 0.266497627862, 0.26754640253, 0.268578571187, 0.269594064632, 0.270592815283, 0.271574757194, 0.272539826082, 0.273487959343, 0.274419096071, 0.27533317708, 0.276230144919, 0.277109943894, 0.277972520087, 0.278817821371, 0.279645797428, 0.280456399768, 0.281249581744, 0.282025298572, 0.282783507341, 0.283524167035, 0.284247238545, 0.284952684683, 0.285640470199, 0.286310561794, 0.286962928133, 0.287597539858, 0.288214369604, 0.288813392005, 0.289394583711, 0.289957923398, 0.290503391778, 0.291030971609, 0.291540647707, 0.292032406954, 0.292506238305, 0.2929621328, 0.29340008357, 0.293820085843, 0.294222136953, 0.294606236347, 0.294972385587, 0.295320588359, 0.295650850475, 0.29596317988, 0.296257586652, 0.29653408301, 0.296792683311, 0.297033404056, 0.29725626389, 0.297461283602, 0.29764848613, 0.297817896552, 0.297969542094, 0.298103452125, 0.298219658154, 0.29831819383, 0.298399094936, 0.298462399391, 0.298508147239, 0.298536380648, 0.298547143907, 0.298540483416, 0.298516447681, 0.298475087309, 0.298416454997, 0.29834060553, 0.298247595766, 0.29813748463, 0.298010333106, 0.297866204223, 0.29770516305, 0.297527276677, 0.297332614212, 0.297121246761, 0.296893247423, 0.29664869127, 0.296387655335, 0.296110218602, 0.295816461986, 0.295506468321, 0.295180322341, 0.29483811067, 0.294479921797, 0.294105846067, 0.293715975656, 0.293310404561, 0.292889228572, 0.292452545263, 0.292000453965, 0.29153305575, 0.29105045341, 0.290552751435, 0.290040055993, 0.289512474911, 0.288970117649, 0.288413095278, 0.287841520462, 0.287255507431, 0.286655171957, 0.286040631333, 0.285412004348, 0.284769411261, 0.284112973781, 0.283442815035, 0.282759059547, 0.282061833214, 0.281351263275, 0.280627478289, 0.279890608106, 0.279140783841, 0.278378137849, 0.277602803694, 0.276814916124, 0.276014611043, 0.275202025481, 0.274377297569, 0.27354056651, 0.272691972546, 0.271831656937, 0.270959761924, 0.270076430707, 0.269181807411, 0.268276037057, 0.267359265537, 0.266431639577, 0.265493306715, 0.264544415265, 0.263585114291, 0.262615553574, 0.261635883584, 0.260646255452, 0.259646820932, 0.258637732379, 0.257619142716, 0.256591205402, 0.255554074403, 0.254507904161, 0.253452849566, 0.252389065923, 0.251316708922, 0.250235934608, 0.249146899354, 0.248049759826, 0.246944672953, 0.245831795902, 0.244711286044, 0.243583300924, 0.242447998233, 0.241305535777, 0.24015607145, 0.238999763199, 0.237836769, 0.236667246829, 0.235491354627, 0.234309250278, 0.233121091577, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    std::vector<double> vkb1 = {6.94671878711e-310, 6.94671878711e-310, 4.63642630903e-310, 4.63642630903e-310, 0.0593024935533, 0.0524839693193, 0.0623451494234, 0.0565580873013, 0.0565580873013, 0.0623451494234, 0.0610038354407, 0.0610038354407, 0.0623451494234, 0.0565580873013, 0.0565580873013, 0.0623451494234, 0.0610038354407, 0.0610038354407, 0.0514646379333, 0.0565580873013, 0.0650603903953, 0.0539633987279, 0.0417118619136, 0.0539633987279, 0.0650603903953, 0.0565580873013, 0.0514646379333, 0.0544200274582, 0.0551211084043, 0.0544200274582, 0.0463285476759, 0.0623451494234, 0.0539633987279, 0.0241295616984, 0.0241295616984, 0.0539633987279, 0.0623451494234, 0.0463285476759, 0.0381442416087, 0.037710474982, 0.037710474982, 0.0381442416087, 0.0495823830815, 0.0610038354407, 0.0417118619136, 0.0241295616984, 0.0417118619136, 0.0610038354407, 0.0495823830815, 0.0315403156644, 0.0248192994607, 0.0230092250029, 0.0248192994607, 0.0315403156644, 0.050867665618, 0.0610038354407, 0.0539633987279, 0.0539633987279, 0.0610038354407, 0.050867665618, 0.0309201030565, 0.0199924574094, 0.0155584226678, 0.0155584226678, 0.0199924574094, 0.0309201030565, 0.0495823830815, 0.0623451494234, 0.0650603903953, 0.0623451494234, 0.0495823830815, 0.0309201030565, 0.018230226381, 0.0122518391344, 0.0103485739084, 0.0122518391344, 0.018230226381, 0.0309201030565, 0.0463285476759, 0.0565580873013, 0.0565580873013, 0.0463285476759, 0.0315403156644, 0.0199924574094, 0.0122518391344, 0.00930160675049, 0.00930160675049, 0.0122518391344, 0.0199924574094, 0.0315403156644, 0.0514646379333, 0.0565580873013, 0.0514646379333, 0.0381442416087, 0.0248192994607, 0.0155584226678, 0.0103485739084, 0.00930160675049, 0.0103485739084, 0.0155584226678, 0.0248192994607, 0.0381442416087, 0.0623451494234, 0.0623451494234, 0.0544200274582, 0.037710474982, 0.0230092250029, 0.0155584226678, 0.0122518391344, 0.0122518391344, 0.0155584226678, 0.0230092250029, 0.037710474982, 0.0544200274582, 0.0593024935533, 0.0610038354407, 0.0551211084043, 0.037710474982, 0.0248192994607, 0.0199924574094, 0.018230226381, 0.0199924574094, 0.0248192994607, 0.037710474982, 0.0551211084043, 0.0610038354407, 0.0524839693193, 0.0610038354407, 0.0544200274582, 0.0381442416087, 0.0315403156644, 0.0309201030565, 0.0309201030565, 0.0315403156644, 0.0381442416087, 0.0544200274582, 0.0610038354407, 0.0524839693193, 0.0537838525063, 0.0463285476759, 0.0463285476759, 0.0537838525063, 0.057641304512, 0.057641304512, 0.0537838525063, 0.0463285476759, 0.0463285476759, 0.0537838525063, 0.057641304512, 0.057641304512, 0.0463285476759, 0.0514646379333, 0.0623451494234, 0.0593024935533, 0.0524839693193, 0.0593024935533, 0.0623451494234, 0.0514646379333, 0.0463285476759, 0.0495823830815, 0.050867665618, 0.0495823830815, 0.0463285476759, 0.0623451494234, 0.0539633987279, 0.0241295616984, 0.0241295616984, 0.0539633987279, 0.0623451494234, 0.0463285476759, 0.0381442416087, 0.037710474982, 0.037710474982, 0.0381442416087, 0.0537838525063, 0.0593024935533, 0.0241295616984, -0.00278087731517, 0.0241295616984, 0.0593024935533, 0.0537838525063, 0.034202478842, 0.0266952083411, 0.0249881776162, 0.0266952083411, 0.034202478842, 0.057641304512, 0.0524839693193, 0.0241295616984, 0.0241295616984, 0.0524839693193, 0.057641304512, 0.0369286147401, 0.0227825612199, 0.0177375442877, 0.0177375442877, 0.0227825612199, 0.0369286147401, 0.057641304512, 0.0593024935533, 0.0539633987279, 0.0593024935533, 0.057641304512, 0.0384845188278, 0.0216517720702, 0.0143474640164, 0.0117194009027, 0.0143474640164, 0.0216517720702, 0.0384845188278, 0.0537838525063, 0.0623451494234, 0.0623451494234, 0.0537838525063, 0.0369286147401, 0.0216517720702, 0.0131561583824, 0.00953161914874, 0.00953161914874, 0.0131561583824, 0.0216517720702, 0.0369286147401, 0.0463285476759, 0.0514646379333, 0.0463285476759, 0.034202478842, 0.0227825612199, 0.0143474640164, 0.00953161914874, 0.00872093243929, 0.00953161914874, 0.0143474640164, 0.0227825612199, 0.034202478842, 0.0463285476759, 0.0463285476759};

    std::vector<std::complex<double>> sk = {{1, 0}, {1, 0}, {1, -0}, {1, -0}, {1, -0}, {1, 0}, {1, -0}, {1, -0}, {1, -0}, {1, -0}, {1, -0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, -0}, {1, -0}, {1, -0}, {1, 0}, {1, -0}, {1, -0}, {1, -0}, {1, -0}, {1, -0}, {1, -0}, {1, 0}, {1, 0}, {1, 0}, {1, -0}, {1, -0}, {1, -0}, {1, -0}, {1, -0}, {1, -0}, {1, -0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {-1, 1.22464679915e-16}, {6.12323399574e-17, 1}, {1, -0}, {6.12323399574e-17, -1}, {-1, -1.22464679915e-16}, {1, 0}, {6.12323399574e-17, -1}, {-1, -1.22464679915e-16}, {-1.83697019872e-16, 1}, {-1, -1.22464679915e-16}, {-1.83697019872e-16, 1}, {-1.83697019872e-16, -1}, {-1, 1.22464679915e-16}, {-1.83697019872e-16, -1}, {-1, 1.22464679915e-16}, {6.12323399574e-17, 1}, {1, 0}, {1, 0}, {6.12323399574e-17, -1}, {-1, -1.22464679915e-16}, {-1.83697019872e-16, 1}, {6.12323399574e-17, -1}, {-1, -1.22464679915e-16}, {-1.83697019872e-16, 1}, {1, 2.44929359829e-16}, {-1.83697019872e-16, 1}, {1, 2.44929359829e-16}, {3.06161699787e-16, -1}, {6.12323399574e-17, 1}, {1, 0}, {6.12323399574e-17, -1}, {-1, -1.22464679915e-16}, {-1.83697019872e-16, 1}, {-1.83697019872e-16, 1}, {1, 2.44929359829e-16}, {3.06161699787e-16, -1}, {3.06161699787e-16, -1}, {-1, -3.67394039744e-16}, {-1.83697019872e-16, -1}, {-1, 1.22464679915e-16}, {-1, 3.67394039744e-16}, {3.06161699787e-16, 1}, {3.06161699787e-16, 1}, {1, -2.44929359829e-16}, {-1.83697019872e-16, -1}, {-1.83697019872e-16, -1}, {-1, 1.22464679915e-16}, {6.12323399574e-17, 1}, {1, 0}, {6.12323399574e-17, 1}, {1, 0}, {6.12323399574e-17, -1}, {3.06161699787e-16, 1}, {1, -2.44929359829e-16}, {-1.83697019872e-16, -1}, {1, -2.44929359829e-16}, {-1.83697019872e-16, -1}, {-1, 1.22464679915e-16}, {6.12323399574e-17, 1}};
    std::vector<std::complex<double>> expected_vkb = {{0.195927788922, 0}, {0.329226319531, 0}, {0.383332042071, -0}, {0.329226319531, -0}, {0.195927788922, -0}, {0.249538315492, 0}, {0.329226319531, -0}, {0.312188331613, -0}, {0.208490058392, -0}, {0.195927788922, -0}, {0.208490058392, -0}, {0.208490058392, 0}, {0.195927788922, 0}, {0.208490058392, 0}, {0.312188331613, 0}, {0.329226319531, 0}, {0.249538315492, 0}, {0.249538315492, 0}, {0.329226319531, -0}, {0.312188331613, -0}, {0.208490058392, -0}, {0.208490058392, 0}, {0.312188331613, -0}, {0.329226319531, -0}, {0.249538315492, -0}, {0.208490058392, -0}, {0.249538315492, -0}, {0.208490058392, -0}, {0.208490058392, 0}, {0.249538315492, 0}, {0.208490058392, 0}, {0.195927788922, -0}, {0.208490058392, -0}, {0.208490058392, -0}, {0.249538315492, -0}, {0.208490058392, -0}, {0.208490058392, -0}, {0.195927788922, -0}, {0.208490058392, 0}, {0.195927788922, 0}, {0.195927788922, 0}, {0.208490058392, 0}, {0.208490058392, 0}, {0.249538315492, 0}, {0.208490058392, 0}, {0.208490058392, 0}, {0.312188331613, 0}, {0.329226319531, 0}, {0.249538315492, 0}, {0.208490058392, 0}, {0.249538315492, 0}, {0.208490058392, 0}, {0.208490058392, 0}, {0.249538315492, 0}, {0.208490058392, 0}, {0.249538315492, 0}, {0.329226319531, 0}, {0.312188331613, 0}, {0.208490058392, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {-5.13801427301e-18, 0.0839101408927}, {-3.79129971818e-18, 0.0619166231573}, {0, -0}, {3.79129971818e-18, -0.0619166231573}, {5.13801427301e-18, -0.0839101408927}, {0, 0}, {3.79129971818e-18, -0.0619166231573}, {7.29376322151e-18, -0.119116192956}, {8.07819105481e-18, -0.131926871657}, {5.13801427301e-18, -0.0839101408927}, {8.07819105481e-18, -0.131926871657}, {-8.07819105481e-18, 0.131926871657}, {-5.13801427301e-18, 0.0839101408927}, {-8.07819105481e-18, 0.131926871657}, {-7.29376322151e-18, 0.119116192956}, {-3.79129971818e-18, 0.0619166231573}, {0, 0}, {-6.17009719415e-18, 0.10076533411}, {-3.79129971818e-18, 0.0619166231573}, {0, -0}, {2.6927303516e-18, -0.0439756238856}, {-2.6927303516e-18, 0.0439756238856}, {0, -0}, {3.79129971818e-18, -0.0619166231573}, {6.17009719415e-18, -0.10076533411}, {2.6927303516e-18, -0.0439756238856}, {6.17009719415e-18, -0.10076533411}, {8.07819105481e-18, -0.131926871657}, {-8.07819105481e-18, 0.131926871657}, {-6.17009719415e-18, 0.10076533411}, {-2.6927303516e-18, 0.0439756238856}, {-5.13801427301e-18, 0.0839101408927}, {-2.6927303516e-18, 0.0439756238856}, {-2.6927303516e-18, 0.0439756238856}, {0, -0}, {2.6927303516e-18, -0.0439756238856}, {2.6927303516e-18, -0.0439756238856}, {5.13801427301e-18, -0.0839101408927}, {2.6927303516e-18, -0.0439756238856}, {5.13801427301e-18, -0.0839101408927}, {-5.13801427301e-18, 0.0839101408927}, {-2.6927303516e-18, 0.0439756238856}, {-2.6927303516e-18, 0.0439756238856}, {0, 0}, {2.6927303516e-18, -0.0439756238856}, {-2.6927303516e-18, 0.0439756238856}, {0, 0}, {3.79129971818e-18, -0.0619166231573}, {6.17009719415e-18, -0.10076533411}, {2.6927303516e-18, -0.0439756238856}, {6.17009719415e-18, -0.10076533411}, {8.07819105481e-18, -0.131926871657}, {-8.07819105481e-18, 0.131926871657}, {-6.17009719415e-18, 0.10076533411}, {-2.6927303516e-18, 0.0439756238856}, {-6.17009719415e-18, 0.10076533411}, {-3.79129971818e-18, 0.0619166231573}, {0, 0}, {2.6927303516e-18, -0.0439756238856}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {-5.13801427301e-18, 0.0839101408927}, {-3.79129971818e-18, 0.0619166231573}, {0, 0}, {3.79129971818e-18, -0.0619166231573}, {5.13801427301e-18, -0.0839101408927}, {-6.17009719415e-18, 0.10076533411}, {-3.79129971818e-18, 0.0619166231573}, {0, 0}, {2.6927303516e-18, -0.0439756238856}, {-5.13801427301e-18, 0.0839101408927}, {-2.6927303516e-18, 0.0439756238856}, {2.6927303516e-18, -0.0439756238856}, {5.13801427301e-18, -0.0839101408927}, {-2.6927303516e-18, 0.0439756238856}, {-0, 0}, {3.79129971818e-18, -0.0619166231573}, {6.17009719415e-18, -0.10076533411}, {-6.17009719415e-18, 0.10076533411}, {-3.79129971818e-18, 0.0619166231573}, {-4.46614189148e-34, 7.29376322151e-18}, {2.6927303516e-18, -0.0439756238856}, {-8.07819105481e-18, 0.131926871657}, {-7.29376322151e-18, 0.119116192956}, {-3.79129971818e-18, 0.0619166231573}, {-3.77809488962e-34, 6.17009719415e-18}, {-8.07819105481e-18, 0.131926871657}, {-6.17009719415e-18, 0.10076533411}, {-2.6927303516e-18, 0.0439756238856}, {-2.6927303516e-18, 0.0439756238856}, {-3.77809488962e-34, 6.17009719415e-18}, {2.6927303516e-18, -0.0439756238856}, {-5.13801427301e-18, 0.0839101408927}, {-2.6927303516e-18, 0.0439756238856}, {-8.07819105481e-18, 0.131926871657}, {-6.17009719415e-18, 0.10076533411}, {-2.6927303516e-18, 0.0439756238856}, {-8.07819105481e-18, 0.131926871657}, {-5.13801427301e-18, 0.0839101408927}, {2.6927303516e-18, -0.0439756238856}, {5.13801427301e-18, -0.0839101408927}, {5.13801427301e-18, -0.0839101408927}, {8.07819105481e-18, -0.131926871657}, {2.6927303516e-18, -0.0439756238856}, {6.17009719415e-18, -0.10076533411}, {8.07819105481e-18, -0.131926871657}, {-2.6927303516e-18, 0.0439756238856}, {-4.46614189148e-34, 7.29376322151e-18}, {3.79129971818e-18, -0.0619166231573}, {6.17009719415e-18, -0.10076533411}, {-2.6927303516e-18, 0.0439756238856}, {-3.77809488962e-34, 6.17009719415e-18}, {2.6927303516e-18, -0.0439756238856}, {2.6927303516e-18, -0.0439756238856}, {6.17009719415e-18, -0.10076533411}, {8.07819105481e-18, -0.131926871657}, {-3.77809488962e-34, 6.17009719415e-18}, {3.79129971818e-18, -0.0619166231573}, {7.29376322151e-18, -0.119116192956}, {8.07819105481e-18, -0.131926871657}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {5.13801427301e-18, -0.0839101408927}, {3.79129971818e-18, -0.0619166231573}, {0, 0}, {-3.79129971818e-18, 0.0619166231573}, {-5.13801427301e-18, 0.0839101408927}, {6.17009719415e-18, -0.10076533411}, {3.79129971818e-18, -0.0619166231573}, {0, 0}, {-2.6927303516e-18, 0.0439756238856}, {5.13801427301e-18, -0.0839101408927}, {2.6927303516e-18, -0.0439756238856}, {-2.6927303516e-18, 0.0439756238856}, {-5.13801427301e-18, 0.0839101408927}, {2.6927303516e-18, -0.0439756238856}, {-0, 0}, {-3.79129971818e-18, 0.0619166231573}, {-6.17009719415e-18, 0.10076533411}, {-0, 0}, {-3.79129971818e-18, 0.0619166231573}, {-7.29376322151e-18, 0.119116192956}, {-8.07819105481e-18, 0.131926871657}, {2.6927303516e-18, -0.0439756238856}, {0, 0}, {-3.79129971818e-18, 0.0619166231573}, {-6.17009719415e-18, 0.10076533411}, {2.6927303516e-18, -0.0439756238856}, {0, 0}, {-2.6927303516e-18, 0.0439756238856}, {-2.6927303516e-18, 0.0439756238856}, {-6.17009719415e-18, 0.10076533411}, {-8.07819105481e-18, 0.131926871657}, {-5.13801427301e-18, 0.0839101408927}, {-8.07819105481e-18, 0.131926871657}, {-2.6927303516e-18, 0.0439756238856}, {-6.17009719415e-18, 0.10076533411}, {-8.07819105481e-18, 0.131926871657}, {-2.6927303516e-18, 0.0439756238856}, {-5.13801427301e-18, 0.0839101408927}, {8.07819105481e-18, -0.131926871657}, {5.13801427301e-18, -0.0839101408927}, {5.13801427301e-18, -0.0839101408927}, {2.6927303516e-18, -0.0439756238856}, {8.07819105481e-18, -0.131926871657}, {6.17009719415e-18, -0.10076533411}, {2.6927303516e-18, -0.0439756238856}, {8.07819105481e-18, -0.131926871657}, {7.29376322151e-18, -0.119116192956}, {3.79129971818e-18, -0.0619166231573}, {-7.55618977925e-34, 1.23401943883e-17}, {8.07819105481e-18, -0.131926871657}, {6.17009719415e-18, -0.10076533411}, {2.6927303516e-18, -0.0439756238856}, {2.6927303516e-18, -0.0439756238856}, {-7.55618977925e-34, 1.23401943883e-17}, {-2.6927303516e-18, 0.0439756238856}, {6.17009719415e-18, -0.10076533411}, {3.79129971818e-18, -0.0619166231573}, {-8.93228378296e-34, 1.4587526443e-17}, {-2.6927303516e-18, 0.0439756238856}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {-0.195927788922, 2.39942339567e-17}, {2.01592979204e-17, 0.329226319531}, {0.383332042071, -0}, {2.01592979204e-17, -0.329226319531}, {-0.195927788922, -2.39942339567e-17}, {0.249538315492, 0}, {2.01592979204e-17, -0.329226319531}, {-0.312188331613, -3.8232044104e-17}, {-3.82990023996e-17, 0.208490058392}, {-0.195927788922, -2.39942339567e-17}, {-3.82990023996e-17, 0.208490058392}, {-3.82990023996e-17, -0.208490058392}, {-0.195927788922, 2.39942339567e-17}, {-3.82990023996e-17, -0.208490058392}, {-0.312188331613, 3.8232044104e-17}, {2.01592979204e-17, 0.329226319531}, {0.249538315492, 0}, {0.249538315492, 0}, {2.01592979204e-17, -0.329226319531}, {-0.312188331613, -3.8232044104e-17}, {-3.82990023996e-17, 0.208490058392}, {1.27663341332e-17, -0.208490058392}, {-0.312188331613, -3.8232044104e-17}, {-6.04778937613e-17, 0.329226319531}, {0.249538315492, 6.11192598663e-17}, {-3.82990023996e-17, 0.208490058392}, {0.249538315492, 6.11192598663e-17}, {6.38316706659e-17, -0.208490058392}, {1.27663341332e-17, 0.208490058392}, {0.249538315492, 0}, {1.27663341332e-17, -0.208490058392}, {-0.195927788922, -2.39942339567e-17}, {-3.82990023996e-17, 0.208490058392}, {-3.82990023996e-17, 0.208490058392}, {0.249538315492, 6.11192598663e-17}, {6.38316706659e-17, -0.208490058392}, {6.38316706659e-17, -0.208490058392}, {-0.195927788922, -7.19827018701e-17}, {-3.82990023996e-17, -0.208490058392}, {-0.195927788922, 2.39942339567e-17}, {-0.195927788922, 7.19827018701e-17}, {6.38316706659e-17, 0.208490058392}, {6.38316706659e-17, 0.208490058392}, {0.249538315492, -6.11192598663e-17}, {-3.82990023996e-17, -0.208490058392}, {-3.82990023996e-17, -0.208490058392}, {-0.312188331613, 3.8232044104e-17}, {2.01592979204e-17, 0.329226319531}, {0.249538315492, 0}, {1.27663341332e-17, 0.208490058392}, {0.249538315492, 0}, {1.27663341332e-17, -0.208490058392}, {6.38316706659e-17, 0.208490058392}, {0.249538315492, -6.11192598663e-17}, {-3.82990023996e-17, -0.208490058392}, {0.249538315492, -6.11192598663e-17}, {-6.04778937613e-17, -0.329226319531}, {-0.312188331613, 3.8232044104e-17}, {1.27663341332e-17, 0.208490058392}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {-5.13801427301e-18, -0.0839101408927}, {-0.0619166231573, 0}, {0, -0}, {-0.0619166231573, -7.58259943636e-18}, {-1.5414042819e-17, 0.0839101408927}, {0, 0}, {-0.0619166231573, -7.58259943636e-18}, {-2.18812896645e-17, 0.119116192956}, {0.131926871657, 3.23127642192e-17}, {-1.5414042819e-17, 0.0839101408927}, {0.131926871657, 3.23127642192e-17}, {0.131926871657, -1.61563821096e-17}, {-5.13801427301e-18, -0.0839101408927}, {0.131926871657, -1.61563821096e-17}, {-7.29376322151e-18, -0.119116192956}, {-0.0619166231573, 0}, {0, 0}, {-6.17009719415e-18, 0.10076533411}, {0.0619166231573, 7.58259943636e-18}, {-0, 0}, {0.0439756238856, 1.07709214064e-17}, {0.0439756238856, 5.3854607032e-18}, {-0, 0}, {0.0619166231573, 1.51651988727e-17}, {3.08504859708e-17, -0.10076533411}, {0.0439756238856, 1.07709214064e-17}, {3.08504859708e-17, -0.10076533411}, {-0.131926871657, -4.84691463288e-17}, {-0.131926871657, 0}, {-6.17009719415e-18, 0.10076533411}, {0.0439756238856, 5.3854607032e-18}, {1.5414042819e-17, -0.0839101408927}, {-0.0439756238856, -1.07709214064e-17}, {-0.0439756238856, -1.07709214064e-17}, {0, 0}, {-0.0439756238856, -1.61563821096e-17}, {-0.0439756238856, -1.61563821096e-17}, {-3.59660999111e-17, 0.0839101408927}, {-0.0439756238856, 5.3854607032e-18}, {5.13801427301e-18, 0.0839101408927}, {-2.56900713651e-17, -0.0839101408927}, {-0.0439756238856, 1.07709214064e-17}, {-0.0439756238856, 1.07709214064e-17}, {0, -0}, {-0.0439756238856, 5.3854607032e-18}, {0.0439756238856, -5.3854607032e-18}, {0, 0}, {0.0619166231573, 0}, {6.17009719415e-18, -0.10076533411}, {0.0439756238856, 0}, {6.17009719415e-18, -0.10076533411}, {-0.131926871657, -1.61563821096e-17}, {-0.131926871657, 3.23127642192e-17}, {1.85102915825e-17, 0.10076533411}, {0.0439756238856, -5.3854607032e-18}, {1.85102915825e-17, 0.10076533411}, {0.0619166231573, -7.58259943636e-18}, {0, 0}, {0.0439756238856, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {-5.13801427301e-18, -0.0839101408927}, {-0.0619166231573, 0}, {0, 0}, {-0.0619166231573, -7.58259943636e-18}, {-1.5414042819e-17, 0.0839101408927}, {-6.17009719415e-18, 0.10076533411}, {0.0619166231573, 7.58259943636e-18}, {0, 0}, {0.0439756238856, 1.07709214064e-17}, {1.5414042819e-17, -0.0839101408927}, {-0.0439756238856, -1.07709214064e-17}, {-0.0439756238856, 5.3854607032e-18}, {5.13801427301e-18, 0.0839101408927}, {0.0439756238856, -5.3854607032e-18}, {0, -0}, {0.0619166231573, 0}, {6.17009719415e-18, -0.10076533411}, {-6.17009719415e-18, 0.10076533411}, {0.0619166231573, 7.58259943636e-18}, {1.33984256744e-33, -7.29376322151e-18}, {0.0439756238856, 1.07709214064e-17}, {0.131926871657, 1.61563821096e-17}, {2.18812896645e-17, -0.119116192956}, {-0.0619166231573, -1.51651988727e-17}, {-1.88904744481e-33, 6.17009719415e-18}, {-0.131926871657, -3.23127642192e-17}, {-3.08504859708e-17, 0.10076533411}, {0.0439756238856, 1.61563821096e-17}, {-0.0439756238856, 0}, {-3.77809488962e-34, 6.17009719415e-18}, {-0.0439756238856, -5.3854607032e-18}, {1.5414042819e-17, -0.0839101408927}, {-0.0439756238856, -1.07709214064e-17}, {-0.131926871657, -3.23127642192e-17}, {-3.08504859708e-17, 0.10076533411}, {0.0439756238856, 1.61563821096e-17}, {0.131926871657, 4.84691463288e-17}, {3.59660999111e-17, -0.0839101408927}, {-0.0439756238856, 5.3854607032e-18}, {5.13801427301e-18, 0.0839101408927}, {2.56900713651e-17, 0.0839101408927}, {0.131926871657, -3.23127642192e-17}, {0.0439756238856, -1.07709214064e-17}, {-1.85102915825e-17, -0.10076533411}, {-0.131926871657, 1.61563821096e-17}, {0.0439756238856, -5.3854607032e-18}, {-4.46614189148e-34, -7.29376322151e-18}, {0.0619166231573, 0}, {6.17009719415e-18, -0.10076533411}, {-0.0439756238856, 0}, {-3.77809488962e-34, 6.17009719415e-18}, {-0.0439756238856, -5.3854607032e-18}, {0.0439756238856, -1.07709214064e-17}, {-1.85102915825e-17, -0.10076533411}, {-0.131926871657, 1.61563821096e-17}, {1.13342846689e-33, 6.17009719415e-18}, {-0.0619166231573, 7.58259943636e-18}, {7.29376322151e-18, 0.119116192956}, {0.131926871657, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {5.13801427301e-18, 0.0839101408927}, {0.0619166231573, 0}, {0, 0}, {0.0619166231573, 7.58259943636e-18}, {1.5414042819e-17, -0.0839101408927}, {6.17009719415e-18, -0.10076533411}, {-0.0619166231573, -7.58259943636e-18}, {0, 0}, {-0.0439756238856, -1.07709214064e-17}, {-1.5414042819e-17, 0.0839101408927}, {0.0439756238856, 1.07709214064e-17}, {0.0439756238856, -5.3854607032e-18}, {-5.13801427301e-18, -0.0839101408927}, {-0.0439756238856, 5.3854607032e-18}, {0, -0}, {-0.0619166231573, 0}, {-6.17009719415e-18, 0.10076533411}, {-0, 0}, {0.0619166231573, 7.58259943636e-18}, {2.18812896645e-17, -0.119116192956}, {-0.131926871657, -3.23127642192e-17}, {-0.0439756238856, -5.3854607032e-18}, {0, 0}, {-0.0619166231573, -1.51651988727e-17}, {-3.08504859708e-17, 0.10076533411}, {0.0439756238856, 1.07709214064e-17}, {-0, 0}, {0.0439756238856, 1.61563821096e-17}, {-0.0439756238856, 0}, {-6.17009719415e-18, 0.10076533411}, {0.131926871657, 1.61563821096e-17}, {1.5414042819e-17, -0.0839101408927}, {-0.131926871657, -3.23127642192e-17}, {-0.0439756238856, -1.07709214064e-17}, {-3.08504859708e-17, 0.10076533411}, {0.131926871657, 4.84691463288e-17}, {0.0439756238856, 1.61563821096e-17}, {3.59660999111e-17, -0.0839101408927}, {-0.131926871657, 1.61563821096e-17}, {5.13801427301e-18, 0.0839101408927}, {2.56900713651e-17, 0.0839101408927}, {0.0439756238856, -1.07709214064e-17}, {0.131926871657, -3.23127642192e-17}, {-1.85102915825e-17, -0.10076533411}, {-0.0439756238856, 5.3854607032e-18}, {-0.131926871657, 1.61563821096e-17}, {7.29376322151e-18, 0.119116192956}, {0.0619166231573, 0}, {-7.55618977925e-34, 1.23401943883e-17}, {0.131926871657, 0}, {6.17009719415e-18, -0.10076533411}, {-0.0439756238856, -5.3854607032e-18}, {0.0439756238856, -1.07709214064e-17}, {2.26685693377e-33, 1.23401943883e-17}, {0.0439756238856, -5.3854607032e-18}, {-1.85102915825e-17, -0.10076533411}, {-0.0619166231573, 7.58259943636e-18}, {-8.93228378296e-34, -1.4587526443e-17}, {-0.0439756238856, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}};

    using delmem_complex_op = psi::memory::delete_memory_op<std::complex<double>, psi::DEVICE_GPU>;
    using resmem_complex_op = psi::memory::resize_memory_op<std::complex<double>, psi::DEVICE_GPU>;
    using syncmem_complex_h2d_op = psi::memory::synchronize_memory_op<std::complex<double>, psi::DEVICE_GPU, psi::DEVICE_CPU>;
    using syncmem_complex_d2h_op = psi::memory::synchronize_memory_op<std::complex<double>, psi::DEVICE_CPU, psi::DEVICE_GPU>;

    using delmem_var_op = psi::memory::delete_memory_op<double, psi::DEVICE_GPU>;
    using resmem_var_op = psi::memory::resize_memory_op<double, psi::DEVICE_GPU>;
    using syncmem_var_h2d_op = psi::memory::synchronize_memory_op<double, psi::DEVICE_GPU, psi::DEVICE_CPU>;
    using syncmem_var_d2h_op = psi::memory::synchronize_memory_op<double, psi::DEVICE_CPU, psi::DEVICE_GPU>;

    using delmem_int_op = psi::memory::delete_memory_op<int, psi::DEVICE_GPU>;
    using resmem_int_op = psi::memory::resize_memory_op<int, psi::DEVICE_GPU>;
    using syncmem_int_h2d_op = psi::memory::synchronize_memory_op<int, psi::DEVICE_GPU, psi::DEVICE_CPU>;

    void SetUp() override {
    }
    void TearDown() override {
    }
};

TEST_F(TestSrcPWVnlMultiDevice, cal_vnl_op_cpu)
{
    std::vector<std::complex<double>> vkb(expected_vkb.size(), 0);

    hamilt::cal_vnl_op<double, psi::DEVICE_CPU>()(
        cpu_ctx,
        ntype, npw, npwx, nhm, NQX,
        tab_2, tab_3,
        atom_na.data(), atom_nb.data(), atom_nh.data(),
        DQ, tpiba, NEG_IMAG_UNIT,
        gk.data(), ylm.data(), indv.data(), nhtol.data(), nhtolm.data(), tab.data(), vkb1.data(), sk.data(),
        vkb.data());

    for (int ii = 0; ii < vkb.size(); ii++) {
        EXPECT_LT(fabs(vkb[ii] - expected_vkb[ii]), 6e-5);
    }
}


#if __CUDA || __UT_USE_CUDA || __ROCM || __UT_USE_ROCM
TEST_F(TestSrcPWVnlMultiDevice, cal_vnl_op_gpu)
{
    std::vector<std::complex<double>> vkb(expected_vkb.size(), 0);
    int * d_atom_na = nullptr, * d_atom_nb = nullptr, * d_atom_nh = nullptr;
    double * d_gk = nullptr, * d_ylm = nullptr, * d_indv = nullptr, * d_nhtol = nullptr, * d_nhtolm = nullptr, * d_tab = nullptr, * d_vkb1 = nullptr;
    std::complex<double> * d_sk = nullptr, * d_vkb = nullptr;

    resmem_int_op()(gpu_ctx, d_atom_na, atom_na.size());
    resmem_int_op()(gpu_ctx, d_atom_nb, atom_nb.size());
    resmem_int_op()(gpu_ctx, d_atom_nh, atom_nh.size());
    syncmem_int_h2d_op()(gpu_ctx, cpu_ctx, d_atom_na, atom_na.data(), atom_na.size());
    syncmem_int_h2d_op()(gpu_ctx, cpu_ctx, d_atom_nb, atom_nb.data(), atom_nb.size());
    syncmem_int_h2d_op()(gpu_ctx, cpu_ctx, d_atom_nh, atom_nh.data(), atom_nh.size());

    resmem_var_op()(gpu_ctx, d_gk, gk.size());
    resmem_var_op()(gpu_ctx, d_ylm, ylm.size());
    resmem_var_op()(gpu_ctx, d_indv, indv.size());
    resmem_var_op()(gpu_ctx, d_nhtol, nhtol.size());
    resmem_var_op()(gpu_ctx, d_nhtolm, nhtolm.size());
    resmem_var_op()(gpu_ctx, d_tab, tab.size());
    resmem_var_op()(gpu_ctx, d_vkb1, vkb1.size());

    syncmem_var_h2d_op()(gpu_ctx, cpu_ctx, d_gk, gk.data(), gk.size());
    syncmem_var_h2d_op()(gpu_ctx, cpu_ctx, d_ylm, ylm.data(), ylm.size());
    syncmem_var_h2d_op()(gpu_ctx, cpu_ctx, d_indv, indv.data(), indv.size());
    syncmem_var_h2d_op()(gpu_ctx, cpu_ctx, d_nhtol, nhtol.data(), nhtol.size());
    syncmem_var_h2d_op()(gpu_ctx, cpu_ctx, d_nhtolm, nhtolm.data(), nhtolm.size());
    syncmem_var_h2d_op()(gpu_ctx, cpu_ctx, d_tab, tab.data(), tab.size());
    syncmem_var_h2d_op()(gpu_ctx, cpu_ctx, d_vkb1, vkb1.data(), vkb1.size());

    resmem_complex_op()(gpu_ctx, d_sk, sk.size());
    resmem_complex_op()(gpu_ctx, d_vkb, vkb.size());

    syncmem_complex_h2d_op()(gpu_ctx, cpu_ctx, d_sk, sk.data(), sk.size());
    syncmem_complex_h2d_op()(gpu_ctx, cpu_ctx, d_vkb, vkb.data(), vkb.size());

    hamilt::cal_vnl_op<double, psi::DEVICE_GPU>()(
            gpu_ctx,
            ntype, npw, npwx, nhm, NQX,
            tab_2, tab_3,
            d_atom_na, d_atom_nb, d_atom_nh,
            DQ, tpiba, NEG_IMAG_UNIT,
            d_gk, d_ylm, d_indv, d_nhtol, d_nhtolm, d_tab, d_vkb1, d_sk,
            d_vkb);

    syncmem_complex_d2h_op()(cpu_ctx, gpu_ctx, vkb.data(), d_vkb, vkb.size());

    for (int ii = 0; ii < vkb.size(); ii++) {
        EXPECT_LT(fabs(vkb[ii] - expected_vkb[ii]), 6e-5);
    }

    delmem_int_op()(gpu_ctx, d_atom_na);
    delmem_int_op()(gpu_ctx, d_atom_nh);
    delmem_int_op()(gpu_ctx, d_atom_nb);

    delmem_var_op()(gpu_ctx, d_gk);
    delmem_var_op()(gpu_ctx, d_ylm);
    delmem_var_op()(gpu_ctx, d_indv);
    delmem_var_op()(gpu_ctx, d_nhtol);
    delmem_var_op()(gpu_ctx, d_nhtolm);
    delmem_var_op()(gpu_ctx, d_tab);
    delmem_var_op()(gpu_ctx, d_vkb1);

    delmem_complex_op()(gpu_ctx, d_sk);
    delmem_complex_op()(gpu_ctx, d_vkb);
}
#endif // __CUDA || __UT_USE_CUDA || __ROCM || __UT_USE_ROCM